<form action="index.php/contract/insert/" method="post" enctype="multipart/form-data" name="myform" id="myform">
<div id="inline1">
<h2><span>合同信息</span></h2>
<table>
        <tr><th colspan="5">基本信息：</th></tr>
        <tr>
        	<td class="name" width="80"><span>*</span>主题：</td>
            <td colspan="4"><input class="text_width" style=" width:427px;" id="subject" name="subject" type="text"></input></td>
        </tr>

        <tr>
            <td class="name" width="80"><span>*</span>对应客户：</td>
            <td colspan="4"><input type="text" style=" width:427px;" autocomplete="off" id="customer_name" name="customer_name" value=<?php echo $customer_name;?>></input></td>
        </tr>

        <tr>
        	<td class="name" width="80"><span>*</span>对应机会：</td>
            <td colspan="4">
            	<select id="opportunity_subject" name="opportunity_id" style="width:427px;">
            		<?php foreach($oppes as $opp_item):?>
            			<option value="<?php echo $opp_item->id;?>"><?php echo $opp_item->subject;?></option>
            		<?php endforeach;?>
                </select>
            </td>
        </tr>
        <tr>
            <td class="name" width="80">合同号：</td>
            <td width="170"><input type="text" name="contract_no" value= ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">总金额：</td>
            <td width="170"><input class="input_bg" name="total_amount" type="text" value= ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">付款方式：</td>
            <td width="170">
            	<select name="payment_type">
                	<option value="支票">支票</option>
                    <option value="现金">现金</option>
                    <option value="银行转帐">银行转帐</option>
                    <option value="其它">其它</option>
                </select>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">交付地点：</td>
            <td width="170"><input class="text_width" name="payment_address" type="text" value= ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">开始时间：</td>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 1px no-repeat;" name="start_time" class="datepicker" value= ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">结束时间：</td>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 1px no-repeat;" class="datepicker" name="end_time" value= ></input></td>
        </tr>
        <tr>
            <td class="name" width="80">产品：</td>
            <td colspan="4"><input type="text" style=" width:427px;"  name="product" value= ></input></td>
        </tr>
        <tr>
        	<td class="name" width="80">客户签约人：</td>
            <td width="170"><input type="text" name="customer_contract" value= ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">我方签约人：</td>
            <td width="170"><input type="text" name="our_contract"  value= ></input></td>
        </tr>
         <?php 
                    		$user_name = $this->session->userdata('username');
                       		$role = $this->session->userdata('role');
                       		?>
        <tr>
        	<td class="name" width="80">所有者：</td>
        	<td width="170">
        	<?php if($role != '商务助理'):?>
            	<input type="text" name="owner_name" value=<?php echo $user_name=$this->session->userdata('username');?> ></input>
            <?php endif;?>
            <?php if($role == '商务助理'):?>
            	<select name="owner_name">
                    	<?php foreach ($all_users as $item_user):?>
                    		<?php if($item_user->user_name != '何俊斌'):?>
                    			<option value="<?= $item_user->user_name?>" <?php if($item_user->user_name == $user_name):?> selected='selected' <?php endif;?>><?= $item_user->user_name?></option>
                    		<?php endif;?>
                        <?php endforeach;?>
            <?php endif;?>
            </td>
            <td>&nbsp;</td>
            <td class="name" width="80">签约时间：</td>
            <td width="170"><input type="text"  style="background:url(images/calendar.gif) right 1px no-repeat;" class="datepicker" name="signing_time"  value=<?= $update_contract->signing_time ?> ></input></td>
        </tr>
        <!--<tr><th colspan="5">执行状态：</th></tr>
        <tr>
            <td class="name" width="80">回款金额：</td>
            <td width="170"><input type="text" name="payment_amount" value= ></input></td>
            <td>&nbsp;</td>
            <td class="name" width="80">状态：</td>
            <td width="170">
            	<select name="status">
                    <option value="执行中">执行中</option>
                    <option value="意外中止">意外中止</option>
                    <option value="完成">完成</option>
                </select>
            </td>
        </tr>-->
        <tr><th colspan="5">其他：</th></tr>
        <tr>
            <td class="gj_name" width="80">合同正文及<br />附件：</td>
            <td colspan="4">
            	<!--<input type="file" name="userfile" size="20" />-->
                <div class="tract_con">
                    <input type="text" class="tract_text" name="textfield" id="textfield" value="" />
                    <input type='button' class="tract_but" value='浏览' />
                    <input type="file" class="tract_file" name="userfile" onchange="document.getElementById('textfield').value=this.value" />
                </div>
            </td>
        </tr>
		<tr>
            <td class="gj_name" width="80">备注：</td>
            <td colspan="4"><textarea name="remark" value= ></textarea></td>
        </tr>
        <tr><td colspan="5">&nbsp;</td></tr>
        <tr class="sub">
            <td colspan="5"><input type="button" id="contract_tijiao" value="提交" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="reset" value="重置" /></td>
        </tr>
    </table>
</div>
</form>
<input type="hidden" id="type" value="1" ></input>
<script type="text/javascript">
$(function() {
		$( ".datepicker" ).datepicker();

		$("#contract_tijiao").click(function(){
			var error="";
			var subject =$("#subject").val();
			var customer_name =$("#customer_name").val();
			var opportunity_subject =$("#opportunity_subject").val();
			if(subject == ''){
				error+="主题不允许为空,请填写\x0d";
				if(subject == ''){
					$("#subject").focus();
				}
			}
			if(customer_name == ''){
				error+="对应客户不允许为空,请填写\x0d";
				if(subject != ''){
					$("#customer_name").focus();
				}
			}
			if(opportunity_subject == null){
				 error+="对应机会不允许为空,请选择\x0d";
			}
			if(error != ""){
		    	alert(error);
		    }else{
		    	var number=$(":input[name='contract_no']").val();
				if(number){
					$.post("index.php/contract/check_contract_number", { number: number },
							   function(data){
							    if(data != ''){
								    alert('合同编号以添加');
								    $(":input[name='contract_no']").focus();
								    $(":input[name='contract_no']").val('');
								}else{
									$("#myform").submit();
								}
					});
				}else{
					$("#myform").submit();
				}
		    }
			})
});
</script>